<template>
	<view>
		<uni-swiper-dot :info="detail.pic" :current="current" field="content" :mode="mode" :dots-styles="dotsStyles">
			<swiper class="swiper-box" @change="change">
				<swiper-item v-for="(item ,index) in detail.pic" :key="index">
					<view class="swiper-item">
						<image :src="item" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>
		<view class="content">
			<view class="title">
				{{detail.name}}
			</view>
			<view class="jf">
				<view>鸭鸭卡 <text>{{detail.source}}</text></view>
				<view>剩余：{{userInfo.source}}</view>
			</view>
			<view class="title2">
				商品规格
			</view>
			<view class="cont2" v-html="detail.specs"></view>
			<view class="title2">
				商品描述
			</view>
			<view class="cont2" v-html="detail.desc"></view>
			<view style="height: 200rpx;"></view>
			<view class="footer">
				<view class="submit" @click="submit">立即兑换</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAction
	} from '../../../common/request';
	export default {
		data() {
			return {
				current: 0,
				mode: 'round',
				dotsStyles: {
					backgroundColor: '#FFF',
					border: '1px #FFF solid',
					color: '#fff',
					selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',
					selectedBorder: '1px rgba(255, 90, 95,0.9) solid'
				},
				detail: {},
				userInfo: {}
			};
		},
		onLoad(option) {
			getAction('/goods/show', {
				id: option.id
			}).then(res => {
				this.detail = res.data
			})
			this.getUserInfo()
		},
		methods: {
			submit(){
				if(this.detail.source > this.userInfo.source){
					uni.showToast({
						icon:'none',
						title:'鸭鸭卡不足'
					})
					return 
				}
				uni.navigateTo({
					url:"/pages/car/exchange/exchange?id="+this.detail.id
				})
			},
			getUserInfo() {
				getAction('/user').then(res => {
					this.userInfo = res.data
				})
			},
			change(e) {
				this.current = e.detail.current;
			}
		}
	}
</script>

<style lang="scss">
	.swiper-box {
		height: 750rpx;

		.swiper-item {
			height: 750rpx;

			image {
				width: 100%;
				height: 750rpx;

				img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.content {
		padding: 30rpx;

		.title {
			font-size: 48rpx;
			margin-top: 30rpx;
			color: #2B2B2B;
			line-height: 58rpx;
		}

		.jf {
			line-height: 58rpx;
			height: 58rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;
			margin-bottom: 10rpx;

			>view:nth-of-type(1) {
				font-size: 32rpx;
				color: rgba(255, 80, 53, 1);

				text {
					font-size: 48rpx;
				}
			}

			>view:nth-of-type(2) {
				color: #A49898;
				font-size: 28rpx;
			}
		}

		.title2 {
			margin-top: 48rpx;
			margin-bottom: 20rpx;
			color: #2B2B2B;
			line-height: 36rpx;
			font-size: 28rpx;
			white-space: pre-line;
		}

		.cont2 {
			color: #4F4F4F;
			line-height: 36rpx;
			font-size: 28rpx;
			white-space: pre-line;
		}

		.footer {
			height: 140rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0 20rpx 0rpx #E4E4E4;
			opacity: 1;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			display: flex;
			align-items: center;
			justify-content: center;

			.submit {
				width: 572rpx;
				height: 80rpx;
				background: #FF5035;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				opacity: 1;
				color: #FFFFFF;
				font-size: 36rpx;
				line-height: 80rpx;
				text-align: center;
			}
		}
	}
</style>